<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends TT_Controller {
	const RECORD_LIMIT =  2;
	
	public function index($page = 1)
	{
		$car_menu = Modules::run('menu/menu/create_car_menu');
		$this->load->model('home_model');
		$this->load->library('ttnavigation');
		$total_records = $this->home_model->count();
		
		$nav = new Ttnavigation($total_records, self::RECORD_LIMIT);
		$nav->set_current($page);
		
		$articles = $this->home_model->get_lastest_articles($page - 1,  self::RECORD_LIMIT, $nav->get_max_page());
		
		$menu = simplexml_load_file(FCPATH . 'data/menucar.xml');
		
		$brands = array();
		$models = array();
		
		foreach($menu as $brand) {
			$brands[(int)$brand['id']] = $brand['name'];
			if(count($brand) > 0)  {
				foreach($brand as $model) {
					$models[(int)$model['id']] = $model['name'];
				}
			}
		}
		
		$this->template->build('homepage', 
			array( 'car_menu' => $car_menu, 'articles' => $articles, 
					'models' => $models, 'brands' => $brands, 'nav' => $nav));
	}
}

/* End of file home.php */
/* Location: ./application/modules/home/controllers/home.php */